﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Traceability.Infrastructure
{
    /// <summary>
    ///仓储
    /// </summary>
    public interface IBaseRepository<T>where T : class
    {
        MyDbContext Context { get; }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns>返回集合</returns>
        IQueryable<T> GetAll();
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t">实体</param>
        /// <returns>返回任务</returns>
        Task<int> Add(T t);
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        Task<int> AddRange(IEnumerable<T> list);
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t">实体</param>
        /// <returns>返回任务</returns>
        Task<int> Update(T t);
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        Task<int> UpdateRange(IEnumerable<T> list);

        /// <summary>
        /// 物理删除单个实体
        /// </summary>
        /// <param name="t">要删除的实体</param>
        /// <returns>返回受影响的行数</returns>
        Task<int> Delete(T t);

        /// <summary>
        /// 根据ID物理删除单个实体
        /// </summary>
        /// <param name="id">实体ID</param>
        /// <returns>返回受影响的行数</returns>
        Task<int> DeleteById(object id);

        /// <summary>
        /// 批量物理删除
        /// </summary>
        /// <param name="list">要删除的实体集合</param>
        /// <returns>返回受影响的行数</returns>
        Task<int> DeleteRange(IEnumerable<T> list);

        /// <summary>
        /// 根据条件物理删除
        /// </summary>
        /// <param name="predicate">删除条件</param>
        /// <returns>返回受影响的行数</returns>
        Task<int> DeleteWhere(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
    }
}
